﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO.Ports;
using System.Text;

namespace DZRemoteController
{
	public class ComPortConfigSection : ConfigurationSection
	{
		[ConfigurationProperty("properties")]
		public SerialPortPropertiesElement Options
		{
			get { return ((SerialPortPropertiesElement)(base["properties"])); }
		}

		[ConfigurationProperty("protocol")]
		public SerialPortProtocolElement Protocol	
		{
			get { return ((SerialPortProtocolElement)(base["protocol"])); }
		}
	}

	public class SerialPortPropertiesElement : ConfigurationElement
	{
		[ConfigurationProperty("portName", IsRequired = true)]
		public string PortName
		{
			get { return ((string)(base["portName"])); }
			set { base["portName"] = value; }
		}

		[ConfigurationProperty("baudRate", DefaultValue = 9600)]
		public int BaudRate
		{
			get { return (Convert.ToInt32(base["baudRate"])); }
			set { base["baudRate"] = value; }
		}

		[ConfigurationProperty("parity")]
		public Parity Parity
		{
			get { return ((Parity)(base["parity"])); }
			set { base["parity"] = value; }
		}

		[ConfigurationProperty("dataBits")]
		public int DataBits
		{
			get { return Convert.ToInt32(base["dataBits"]); }
			set { base["dataBits"] = value; }
		}

		[ConfigurationProperty("stopBits")]
		public StopBits StopBits
		{
			get { return ((StopBits)(base["stopBits"])); }
			set { base["stopBits"] = value; }
		}
		
	}


	public class SerialPortProtocolElement : ConfigurationElement
	{
		[ConfigurationProperty("refreshByte", IsRequired = true)]
		public byte RefreshByte
		{
			get { return ((byte)(base["refreshByte"])); }
			set { base["refreshByte"] = value; }
		}

		[ConfigurationProperty("startByte", IsRequired = true)]
		public byte StartByte
		{
			get { return ((byte)(base["startByte"])); }
			set { base["startByte"] = value; }
		}

		[ConfigurationProperty("stopByte", IsRequired = true)]
		public byte StopByte
		{
			get { return ((byte)(base["stopByte"])); }
			set { base["stopByte"] = value; }
		}

		[ConfigurationProperty("stopPackageByte", IsRequired = true)]
		public byte StopPackageByte
		{
			get { return ((byte)(base["stopPackageByte"])); }
			set { base["stopPackageByte"] = value; }
		}

		[ConfigurationProperty("startPackageByte", IsRequired = true)]
		public byte StartPackageByte
		{
			get { return ((byte)(base["startPackageByte"])); }
			set { base["startPackageByte"] = value; }
		}

		[ConfigurationProperty("clearInterval", IsRequired = true)]
    public int ClearInterval
		{
			get { return ((int)(base["clearInterval"])); }
			set { base["clearInterval"] = value; }
		}

		[ConfigurationProperty("disconnectedEvent", IsRequired = true)]
		public byte DisconnectedEvent
		{
			get { return ((byte)(base["disconnectedEvent"])); }
			set { base["disconnectedEvent"] = value; }
		}

		[ConfigurationProperty("connectedEvent", IsRequired = true)]
		public byte ConnectedEvent
		{
			get { return ((byte)(base["connectedEvent"])); }
			set { base["connectedEvent"] = value; }
		}


	}

}
